<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta
			http-equiv="origin-trial"
			content="Atzk/dTch1Tt8qYq/UwLn6aWawymlc3xOKy3xiuwsaj1HBK6eCTBb+EGOnv7LK+oSQ8Fr1l/qykGHhK64mAn+w4AAABjeyJvcmlnaW4iOiJodHRwczovL2hwdWdpcy5naXRodWIuaW86NDQzIiwiZmVhdHVyZSI6IldlYkdQVSIsImV4cGlyeSI6MTY5MTcxMTk5OSwiaXNTdWJkb21haW4iOnRydWV9"
		/>
		<title>directionalLightShadow</title>
		<!-- <link rel="stylesheet" href="./index.scss" /> -->
		<style>
			* {
				box-sizing: border-box;
			}

			html {
				background: #692a84;
				background: linear-gradient(316deg, #0e0f2a, #060913);
				height: 100%;
				width: 100%;
			}

			body {
				font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
				overflow: hidden;
				height: 100%;
				width: 100%;
				margin: 0;
				padding: 0;
			}

			#app {
				height: 100%;
				width: 100%;
			}
		</style>
		<!-- <script type="module" src="../dist/index.js"></script> -->
	</head>

	<body>
		<div id="app"></div>
		<script type="module">
			import {
				BoxGeometry,
				Mesh,
				PerspectiveCamera,
				OrthographicCamera,
				Scene,
				BlinnPhongMaterial,
				Vector3,
				Color,
				SpotLight,
				DirectionalLight,
				Texture,
				Sampler,
				TorusKnotGeometry,
				SkyBox,
				CubeTextureLoader,
				SphereGeometry,
				PbrMaterial,
				loadTexture,
				OrbitControl,
				PlaneGeometry,
				AmbientLight
			} from "../../dist/index.js";

			const init = async () => {
				const scene = new Scene({
					container: "app"
				});

				const camera = new PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.01, 1000);
				camera.position.set(-40, 60, -40);
				camera.lookAt(0, 0, 0);
				scene.setCamera(camera);
				const control = new OrbitControl(camera, document.getElementById("app"));
				control.zoomSpeed = 2.0;
				control.maxPolarAngle = Math.PI / 2;

				const ambientLight = new AmbientLight(new Vector3(0.25, 0.25, 0.25), 0.1);

				const environmentUrls = [
					`../textures/environment/px.jpg`,
					`../textures/environment/nx.jpg`,
					`../textures/environment/py.jpg`,
					`../textures/environment/ny.jpg`,
					`../textures/environment/pz.jpg`,
					`../textures/environment/nz.jpg`
				];
				const skybox = new SkyBox(environmentUrls);

				const directionalLight = new DirectionalLight(new Vector3(1.0, 1.0, 1.0), 1.0, true, {
					openCSM: false
				});
				directionalLight.position.set(30, 40, -8);

				const boxGeometry = new BoxGeometry(10, 10, 10);
				const boxMaterial = new BlinnPhongMaterial(Color.fromCssColorString("#ffffff"), 150);
				boxMaterial.color = new Color(1.0, 0.0, 0.0);
				const boxPrimitive = new Mesh(boxGeometry, boxMaterial);
				boxPrimitive.position.set(-30, 5, 3);

				const torusKnotGeometry = new TorusKnotGeometry(10, 3, 200, 32);
				const torusKnotMaterial = new BlinnPhongMaterial(Color.fromCssColorString("#ffffff"), 150);
				torusKnotMaterial.color = new Color(1.0, 0.0, 0.0);
				const torusKnotPrimitive = new Mesh(torusKnotGeometry, torusKnotMaterial);
				torusKnotPrimitive.position.set(10, 20, -20);

				const sphereGeometry = new SphereGeometry(3);
				const sphereMaterial = new BlinnPhongMaterial(Color.fromCssColorString("#222222"), 150);
				sphereMaterial.color = new Color(0.0, 1.0, 0.0);
				const spherePrimitive = new Mesh(sphereGeometry, sphereMaterial);
				spherePrimitive.position.set(20, 10, 20);

				const groundGeometry = new PlaneGeometry(100, 100);
				const groundMaterial = new BlinnPhongMaterial(Color.fromCssColorString("#111111"), 150);
				groundMaterial.color = new Color(0.78, 0.85, 0.86);
				const ground = new Mesh(groundGeometry, groundMaterial);
				ground.rotateX(Math.PI / 2);

				scene.add(boxPrimitive);
				scene.add(boxPrimitive);
				scene.add(torusKnotPrimitive);
				scene.add(spherePrimitive);
				scene.add(ground);
				scene.add(skybox);
				scene.add(ambientLight);
				scene.add(directionalLight);

				var radiu = 40;
				var i = 0;
				function animate() {
					i++;
					var rad = (i * Math.PI) / 180;
					var x = Math.sin(rad) * radiu;
					var z = Math.cos(rad) * radiu;
					directionalLight.position = new Vector3(x, 40, z);
					torusKnotPrimitive.rotateX(0.01);
					requestAnimationFrame(animate);
					control.update();
					scene.render();
				}
				// document.body.appendChild(scene.context.canvas);
				animate();
				//scene.render()
			};
			init();
		</script>
	</body>
</html>
